package Model.DateProfile;

import java.sql.ResultSet;
import java.sql.Statement;

import DBAccess.DBAccess;
import Model.User;

public class Questionnaire {
	public Boolean loginFlag;

	public User myUser;

	// inputs information into personaldb from questionnaire, returns the userid
	// if successful
	public static int personalInput(int userID, String myAddress, int myHeight,
			int myWeight, int bYear, int bMonth, int bDate, String myInterests,
			int myGender, int myOrientation, int myNewsletterFlag,
			int myNotificationFlag, String myReligion, String myEthnicity) {
		new DBAccess();
		Statement st = null;
		ResultSet rs = null;

		if (myAddress == null || myHeight <= 0 || myWeight <= 0
				|| myInterests == null || myEthnicity == null
				|| myReligion == null || (myGender != 1 && myGender != 2)
				|| (myOrientation != 1 && myOrientation != 2)
				|| (myNewsletterFlag != 0 && myNewsletterFlag != 1)
				|| (myNotificationFlag != 0 && myNotificationFlag != 1)) {
			return -1;
		}
		try {
			DBAccess.updateInfo(userID, myAddress, myHeight, myWeight, bYear,
					bMonth, bDate, myInterests, myGender, myOrientation,
					myNewsletterFlag, myNotificationFlag, myEthnicity,
					myReligion);
			return userID;
		}

		catch (Exception e) {
			e.printStackTrace();
		}
		DBAccess.close(st, rs);
		return 0;
	}

	// inputs information into preferencedb from questionnaire, returns the
	// userid if successful
	public static int preferenceInput(int userID, int weightLowerPref,
			int weightHigherPref, int heightLowerPref, int heightHigherPref,
			int ageLowerPref, int ageHigherPref, String ethnicityPref,
			String religionPref, int gender) {
		new DBAccess();
		Statement st = null;
		ResultSet rs = null;

		if (userID <= 0
				|| (weightLowerPref <= 0 || weightLowerPref > weightHigherPref)
				|| (heightLowerPref <= 0 && heightLowerPref > heightHigherPref)
				|| (ageLowerPref <= 16 || ageLowerPref > ageHigherPref)
				|| ethnicityPref == null || religionPref == null) {
			return -1;
		}
		try {
			DBAccess.insertPreference(userID, weightLowerPref,
					weightHigherPref, heightLowerPref, heightHigherPref,
					ageLowerPref, ageHigherPref, ethnicityPref, religionPref,
					gender);
			return userID;
		}

		catch (Exception e) {
			e.printStackTrace();
		}
		DBAccess.close(st, rs);
		return -1;
	}

}
